package com.mes.controller.manu;

import com.mes.service.manu.fzJobWriteInRfidListService;
import com.interf.agv.AGVUtil;
import com.yy.base.page.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 飞织作业
 */
@Controller
@RequestMapping("fzJobWriteIn")
public class fzJobWriteInRfidListController {
    @Autowired
    private fzJobWriteInRfidListService fzJobWriteInRfidListService;

    //加载飞织作业单
    @ResponseBody
    @RequestMapping(value="selectFlyWeavList",method= RequestMethod.POST)
    public Message selectFlyWeavList(HttpServletRequest request) {
        Message msg = new Message();
        Map map = new HashMap<String,String>();
        map.put("flyWeav", request.getParameter("flyWeav"));
        map.put("status", request.getParameter("status"));
        map.put("jobCode", request.getParameter("jobCode"));

        msg.setSplitPageList(fzJobWriteInRfidListService.selectFlyWeavList(map));

        return msg;
    }
    //加载飞织机台
    @ResponseBody
    @RequestMapping(value="selectFlyWeavs",method= RequestMethod.POST)
    public Message selectFlyWeavs(HttpServletRequest request){
        Message msg = new Message();
        msg.setData("flyWeavs",fzJobWriteInRfidListService.selectFlyWeavs());
        msg.setData("jobStatus",fzJobWriteInRfidListService.selectJobStatus());
        return msg;
    }

    //修改工单是否录入辅料RFID状态
    @ResponseBody
    @RequestMapping(value="updateJobStatus",method= RequestMethod.POST)
    public Message updateJobStatus(HttpServletRequest request){
        Message msg = new Message();

        String jobCode  = request.getParameter("jobCode");
        fzJobWriteInRfidListService.UpdateJobMaterialok(jobCode);
        return msg;
    }

    //调用agv接口
    @ResponseBody
    @RequestMapping(value="callAgv",method= RequestMethod.POST)
    public Message callAgv(HttpServletRequest request){
        String position  = request.getParameter("POSITION");
        String [] ps = position.split(",");
        String jsonStr= "{" +
                "\"agv_id\":\"40241\"," +
                "\"dest_position\":{" +
                "\"x\": " + ps[0] + "," +
                "\"y\": " + ps[1] +
                "}" +
                "}";
        return AGVUtil.sendAGVTask(jsonStr, 0x0001000a);
    }
}
